package com.question.view.command.play;

import java.util.List;

import com.question.Design.SingletonMode;
import com.question.entity.Answer;
import com.question.entity.User;
import com.question.service.IPlayerService;
import com.question.utils.InputOutUtils;

public class AcceptCommand extends PlayerSuper{
	private IPlayerService playerService = SingletonMode.getPlayerService();
	@Override
	protected void exec(User player) {
		InputOutUtils.print("输入问题ID");
		Integer qId = InputOutUtils.inputInteger("ID:");
		List<Answer> list = playerService.isaccepted(player,qId);
		if(list == null) {
			InputOutUtils.print("该问题已经有采纳的答案或者改问题不是你提出的无法采纳");
			return;
		}
		printAnswer(list);
		InputOutUtils.print("请输入要采纳的答案的ID");
		Integer id = InputOutUtils.inputInteger("ID:");
		playerService.acceptAnswer(id,qId);
		InputOutUtils.print("设置完成");
	}
	public void printAnswer(List<Answer> list) {
		for(int i = 0 ; i< list.size();i++) {
			Answer answer = list.get(i);
			InputOutUtils.print("*************************",
								"id:"+answer.getId(),
								"回答:"+answer.getAnswer_info(),
								"回答人:"+ answer.getUser().getDisplay_name(),
								"当前状态:"+(answer.getAnswer_state()==1?"已采纳":"未采纳"),
								"*************************");
			
		}
	}

}
